#include "doorbell_button.h"
#include "button_adc.h"

static button_handle_t front_button = NULL;
static button_handle_t back_button = NULL;

void doorbell_button_init(void)
{
    button_config_t btn_cfg = {0};
    button_adc_config_t btn_adc_cfg = {
        .unit_id = ADC_UNIT_1,
        .adc_channel = 7,
        .button_index = 0,
        .min = 0,
        .max = 50,
    };

    ESP_ERROR_CHECK(iot_button_new_adc_device(&btn_cfg, &btn_adc_cfg, &front_button));
    btn_adc_cfg.button_index = 1;
    btn_adc_cfg.min = 1485,
    btn_adc_cfg.max = 1815;
    ESP_ERROR_CHECK(iot_button_new_adc_device(&btn_cfg, &btn_adc_cfg, &back_button));
}

void doorbell_button_register_front_callback(button_event_t event, button_cb_t callback, void *arg)
{
    iot_button_register_cb(front_button, event, NULL, callback, arg);
}

void doorbell_button_register_back_callback(button_event_t event, button_cb_t callback, void *arg)
{
    iot_button_register_cb(back_button, event, NULL, callback, arg);
}

void doorbell_button_deinit(void)
{
    iot_button_delete(front_button);
    iot_button_delete(back_button);
}
